<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style>
			*{
				font-size:15px;
			}
			input{
				border:0;
				outline: none;
			}
			table,td{
				border:2px solid #000;
			}
			table{
				border-collapse: collapse;
				}
			.right input{
				text-align: center;
				width:100px;
			}
		</style>
	</head>
	<body>
		<table>
			<tr>
				<td>书名</td>
				<td>价格</td>
			</tr>
			<tr>
				<td><input value="看得见风景的房间"></td>
				<td class="right"><input value="¥30.00"></td>
			</tr>
			<tr>
				<td><input value="幸福在哪里"></td>
				<td class="right"><input value="¥18.50"></td>
			</tr>
			<tr>
				<td><input value="60个瞬间"></td>
				<td class="right"><input value="¥32.00"></td>
			</tr>
		</table>
		<button>增加一行</button>
	    <button>删除第二行</button>
		<button>修改标题样式</button>
		<button>复制最后一行</button>
		<script>
//			获取节点
         var trs = document.getElementsByTagName("tr");
         console.log(trs);
         var btn = document.getElementsByTagName("button");
         var table = document.getElementsByTagName("table");
//       console.log(btn);
        //给增加一行添加点击事件
         btn[0].onclick = function(){
         	var tr1 = document.createElement("tr");
         	tr1.innerHTML="<td><input value='小王子'></td><td class='right'><input value='¥22.00'></td>";
            trs[0].parentNode.insertBefore(tr1,trs[2]);
//       	console.log(trs[0].parentNode);
         }
         //给删除第二行添加点击事件
         btn[1].onclick = function(){
         	trs[0].parentNode.removeChild(trs[1]);
         }
        //给修改样式添加点击事件
        btn[2].onclick = function(){
        	trs[0].style.background = "#ccc";
        	trs[0].style.fontWeight = "bold";
        	trs[0].style.textAlign = "center";
        }
        btn[3].onclick = function(){
        var a =	trs[trs.length-1].cloneNode(true);
        trs[0].parentNode.insertBefore(a,trs[trs.length-1]);
        }
		</script>
	</body>
</html>
